package com.bw.user_module.edtuser;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bw.common.field.EventBusEntity;
import com.bw.common.mvvm.view.BaseActivity;
import com.bw.common.photo.PhotoActivity;
import com.bw.user_module.BR;
import com.bw.user_module.R;
import com.bw.user_module.databinding.ActivityEdtBinding;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

@Route(path = "/user/edtuser")
public class EdtUserActivity extends BaseActivity<ActivityEdtBinding,EdtUserViewModel> {
    @Override
    public int bindLayout() {
        return R.layout.activity_edt;
    }

    @Override
    public int vrId() {
        return BR.vm;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void lauchPhoto(EventBusEntity entity){
        if (entity.action.equals("photo")){
            startActivityForResult(new Intent(this, PhotoActivity.class),100);
        }

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100&&resultCode == RESULT_OK){
           String photo= data.getExtras().getString("photo");
           vm.photo.set(photo);
        }
    }
}
